<!DOCTYPE html>
<html>

<head>
    <#include "/yq/admin/components/meta.html" />
    <title>蓁奕科技 ${metaTitleSuffix!}</title>
    <#include "/yq/admin/components/stylesheets.html" />
</head>

<body>
    <div id='app'>
        <el-container>
            <#assign menuIndex="2-1" />
            <#include "/yq/admin/components/menu.html" />
            <el-container>
                <#include "/yq/admin/components/header.html" />
                <el-main>
                    <template>
                        <el-row class="search">
                            <el-date-picker v-model="dateRange" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" unlink-panels="true" :default-value="new Date">
                            </el-date-picker>
                            <el-input v-model="outTradeNo" clearable placeholder="商户单号" style="width: 217px;"></el-input>
                            <el-input v-model="transactionId" clearable placeholder="微信单号" style="width: 217px;"></el-input>
                        </el-row>
                        <el-row class="search">
                            <!-- <el-select v-model="productType" clearable placeholder="商品属性">
                                <el-option :value="1" label="默认商品"></el-option>
                                <el-option :value="2" label="餐饮优惠券"></el-option>
                                <el-option :value="3" label="门票"></el-option>
                                <el-option :value="4" label="报名"></el-option>
                            </el-select> -->
                            <el-select v-model="shopId" clearable filterable placeholder="商户" v-if="${userRole!2} != 2">
                                <el-option v-for="item in shops" :key="item.id" :label="item.name" :value="item.id">
                                </el-option>
                            </el-select>
                            <el-select v-model="categoryId" clearable filterable placeholder="商品类型">
                                <el-option :value="item.id" :label="item.title" v-for="(item, index) in categories"></el-option>
                            </el-select>
                            <el-select v-model="status" clearable placeholder="支付状态">
                                <el-option :value="0" label="未支付"></el-option>
                                <el-option :value="1" label="已支付"></el-option>
                                <el-option :value="-1" label="退款"></el-option>
                                <el-option :value="2" label="关闭"></el-option>
                            </el-select>
                            <el-button @click="onSearch"><i class="el-icon-search"></i>筛选</el-button>
                            <el-button @click="goDownload">下载</el-button>
                        </el-row>
                        <el-table :data="items" style="width: 100%">
                            <el-table-column prop="addTime" label="日期">
                            </el-table-column>
                            <el-table-column prop="out_trade_no" label="商户单号">
                            </el-table-column>
                            <!-- <el-table-column prop="transaction_id" label="微信单号">
                            </el-table-column> -->
                            <el-table-column prop="total_fee" label="金额" width="80">
                                <template slot-scope="scope">
                                    {{ scope.row.total_fee | div100 }}
                                </template>
                            </el-table-column>
                            <el-table-column prop="paid" label="支付金额" width="80">
                                <template slot-scope="scope">
                                    {{ scope.row.paid | div100 }}
                                </template>
                            </el-table-column>
                            <!-- <el-table-column prop="nickName" label="微信">
                            </el-table-column>
                            <el-table-column prop="openid" label="openid">
                            </el-table-column> -->
                            <el-table-column prop="mobile" label="电话">
                            </el-table-column>
                            <el-table-column prop="body" label="内容">
                            </el-table-column>
                            <!-- <el-table-column prop="detail" label="内容">
                            </el-table-column> -->
                            <el-table-column prop="trade_state" label="支付状态">
                            </el-table-column>
                            <el-table-column prop="orderType" label="类型" width="70">
                                <template slot-scope="scope">
                                    <span v-if='scope.row.orderType ==0'>未知</span>
                                    <span v-if='scope.row.orderType ==1'>商品</span>
                                    <span v-if='scope.row.orderType ==2'>团购</span>
                                    <span v-if='scope.row.orderType ==3'>第三方</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="status" label="类型" width="70">
                                <template slot-scope="scope">
                                    <span v-if='scope.row.status ==0'>未支付</span>
                                    <span v-if='scope.row.status ==1'>已支付</span>
                                    <span v-if='scope.row.status ==-1'>退款</span>
                                    <span v-if='scope.row.status ==-2'>关闭</span>
                                    <span v-if='scope.row.status ==-3'>未支付成功</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="name" label="商户">
                            </el-table-column>
                            <el-table-column prop="shopUserName" label="核销员">
                            </el-table-column>
                            <el-table-column label="操作" width="300">
                                <template slot-scope="scope">
                                    <!-- <el-button type="text" @click="detail(scope.row)" v-if='scope.row.orderType == 1 || scope.row.orderType == 2'>查看</el-button> -->
                                    <el-button type="text" @click="detail(scope.row)">查看</el-button>
                                    <el-button type="text" @click="onUpdateOrder(scope.row)">更新</el-button>
                                    <el-button type="text" @click="onUpdateTrackNo(scope.row)">更新物流号</el-button>
                                    <el-button type="text" @click="showExtra(scope.row)" v-if="scope.row.remark">额外信息</el-button>
                                    <el-button type="text" @click="onRefund(scope.row)" v-if='scope.row.status ==1'>退款</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <label class="count" v-if="count">总计：{{count}}元</label>
                        <#include '/components/page.html' />
                    </template>
                </el-main>
            </el-container>
        </el-container>
        <#include "/yq/admin/components/footer.html" />
    </div>
    <#include "/yq/admin/components/scripts.html" />
    <script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data() {
            return {
                status: '${status!}' ? Number('${status!}') : '',
                items: toJson(`${data}`),
                dateRange: '',
                shopId: '${shopId!}' ? Number('${shopId!}') : '',
                shops: toJson(`${shops}`),
                // productType: '${productType!}' ? Number('${productType!}') : '',
                categoryId: '${categoryId!}' ? Number('${categoryId!}') : '',
                categories: toJson(`${categories!}`),
                outTradeNo: '${outTradeNo!}',
                transactionId: '${transactionId!}',
                count: '${sum!}'
            }
        },
        mounted: function() {
            var startTime = '${startTime!""}'
            if (startTime != '') {
                this.dateRange = new Array;
                this.dateRange.push('${startTime!}');
                this.dateRange.push('${endTime!}');
            }
        },
        methods: {
            detail(info) {
                window.location.href = "/yq/admin/order/info?orderId=" + info.id
            },
            onUpdateTrackNo(info) {
                vue.$prompt('物流号', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                }).then(({ value }) => {
                    if (value == '') {
                        return;
                    }
                    alert(value)
                    var param = {
                        orderId: info.id,
                        trackNo: value,
                    }
                    console.log(param)
                    alert(value)
                    axiosRequest(param, '/yq/admin/order/updateTrackNo', '')
                    alert(value)
                }).catch(() => {});
            },
            onRefund(info) {
                this.$confirm('确定退款?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    var param = {
                        orderId: info.id
                    }
                    axiosRequest(param, '/yq/admin/order/refund', '')
                }).catch(() => {});
            },
            onUpdateOrder(info) {
                var param = {
                    orderId: info.id
                }
                axiosRequest(param, '/yq/admin/order/query', '')
            },
            showExtra(info) {
                this.$alert(info.remark, '额外信息', {
                    confirmButtonText: '确定',
                    callback: action => {}
                });
            },
            onDateChange(val) {
                var keys = [
                    { key: 'startDate', value: val[0] },
                    { key: 'endDate', value: val[1] }
                ]
                goPage(1, keys)
            },
            onSearch() {
                var self = this;
                var keys = [
                    { key: 'shopId', value: self.shopId },
                    // { key: 'productType', value: self.productType }
                    { key: 'categoryId', value: self.categoryId },
                    { key: 'status', value: self.status },
                    { key: 'outTradeNo', value: self.outTradeNo },
                    { key: 'transactionId', value: self.transactionId }
                ]

                if (self.dateRange != null && self.dateRange.length > 1) {
                    keys.push({ key: 'startTime', value: self.dateRange[0] });
                    keys.push({ key: 'endTime', value: self.dateRange[1] });
                } else {
                    keys.push({ key: 'startTime', value: '' });
                    keys.push({ key: 'endTime', value: '' });
                }
                goPage(1, keys);
            }
        },
        filters: {
            div100(arg1, arg2) {
                var t1 = 0,
                    r1;
                try { t1 = arg1.toString().split(".")[1].length; } catch (e) {}
                // with (Math) {
                r1 = Number(arg1.toString().replace(".", ""));
                return (r1 / 100) * Math.pow(10, -t1);
                // }
            }
        }
    })
    </script>
    <script>
        // vue.tableData = ${items!};
    </script>
    <style type="text/css">
    .search {
        margin-top: 10px;
    }

    .count {
        /*margin-top: 20rpx;*/
        margin-left: 900px;
        font-size: 13px;
        position: relative;
        top: 32px;
    }
    </style>
</body>

</html>